package com.example.experiment2;

import android.support.constraint.ConstraintLayout;
import android.support.constraint.ConstraintSet;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class UC1 extends AppCompatActivity {

    Button btn1,btn2,btn3,btn4,back;
    LinearLayout linearLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc1);
        linearLayout=findViewById(R.id.UC1_Linear);
        btn1=findViewById(R.id.UC1_btn1);
        btn2=findViewById(R.id.UC1_btn2);
        btn3=findViewById(R.id.UC1_btn3);
        btn4=findViewById(R.id.UC1_btn4);
        back=findViewById(R.id.UC1_back);
        btn1.setOnClickListener(new ViewOnClick());
        btn2.setOnClickListener(new ViewOnClick());
        btn3.setOnClickListener(new ViewOnClick());
        btn4.setOnClickListener(new ViewOnClick());
        back.setOnClickListener(new ViewOnClick());
    }
    class ViewOnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            ConstraintLayout constraintLayout=findViewById(R.id.UC1_constraint);
            ConstraintSet set=new ConstraintSet();
            set.clone(constraintLayout);
            switch (v.getId()){
                case R.id.UC1_btn1:
                    if(linearLayout.getOrientation()!=LinearLayout.HORIZONTAL){
                        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                    }
                    break;
                case R.id.UC1_btn2:
                    if(linearLayout.getOrientation()!=LinearLayout.VERTICAL){
                        linearLayout.setOrientation(LinearLayout.VERTICAL);
                    }
                    break;
                case R.id.UC1_btn3:
                    set.connect(R.id.UC1_Linear,ConstraintSet.RIGHT,R.id.UC1_Linear,ConstraintSet.LEFT);
                    set.applyTo(constraintLayout);
                    break;
                case R.id.UC1_btn4:
                    set.connect(R.id.UC1_Linear,ConstraintSet.RIGHT,ConstraintSet.PARENT_ID,ConstraintSet.RIGHT);
                    set.applyTo(constraintLayout);
                    break;
                case R.id.UC1_back:
                    finish();
                    break;
            }
        }
    }
}
